import unittest
from ddt import ddt,data,unpack
import requests
from Common.readExcel import ReadExcel
from Common.configHttp import ConfigHttp
from Common.WriteExcel import WriteExcel

#1、准备数据
#实例化对象
res=ReadExcel()
#调用方法
result_data=res.read()

#定义一个类
@ddt
class TestCase(unittest.TestCase):
    #获取测试数据内的关键数据
    @data(*result_data)
    #自动解包
    @unpack
    def testrun(self,id,interfaceUrl,name,method,value,expect,real,status):
        ch_re=ConfigHttp(method,interfaceUrl,value)
        re=ch_re.run()
        res_dict=re.json()
        print(res_dict)
        res=res_dict['errorCode']
        if res==int(expect):
            status='pass'
            print('pass')
        else:
            status='fail'
            print('fail')
        self.assertEqual(res_dict["errorCode"],int(expect),"测试用例执行不通过！")

if __name__ == '__main__':
    unittest.main(verbosity=2)
